package com.csii.activiti.server.core.entity;

import cn.hutool.core.collection.CollUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
@Data
@ApiModel("多实列")
public class ActFlowMultiNode {
    @ApiModelProperty("单实列")
    private List<ActFlowNode> nodes;
    //兼容以前的单条件
    @ApiModelProperty("条件")
    private List<ActFlowCondition> conditions;
    @ApiModelProperty("条件组")
    private List<ActFlowConditionGroup> conditionGroups;

    public List<ActFlowConditionGroup> employConditionGroups(){
        if (CollUtil.isNotEmpty(conditions)){
            return CollUtil.newArrayList(new ActFlowConditionGroup(conditions));
        }
        if (CollUtil.isNotEmpty(conditionGroups)){
            return conditionGroups;
        }
        return null;
    }

    public List<ActFlowCondition> employCondition(){
        if (CollUtil.isNotEmpty(conditions)){
            return conditions;
        }
        if (CollUtil.isNotEmpty(conditionGroups)){
            List<ActFlowCondition> conditionAll = new ArrayList<>();
            for (ActFlowConditionGroup conditionGroup : conditionGroups) {
                conditionAll.addAll(conditionGroup.getConditions());
            }
            return conditionAll;
        }
        return new ArrayList<>();
    }
}
